package com.example.demo.controller;

import com.example.demo.config.SendSMS;
import com.example.demo.pojo.ChengJi;
import com.example.demo.pojo.XueSheng;
import com.example.demo.service.impl.ChengJiServiceImpl;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 成绩表(ChengJi)表控制层
 *
 * @author 小虾米大侠
 * @since 2021-03-17 23:14:19
 * @version 1.0
 */
@RestController
@RequestMapping("chengJi")
@Api(value = "成绩表(ChengJi)管理",tags = "成绩表(ChengJi)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class ChengJiController {
    /**
     * 服务对象
     */
    @Resource
    private ChengJiServiceImpl chengJiServiceImpl;

    @Resource
    private SendSMS sendSMS;

    /**
     * 分页查询
     * @param page
     * @param keMuMingCheng
     * @param xueFen
     * @param xingMing
     * @param nianJi
     * @param lfenShu
     * @param rfenShu
     * @return
     */
    @RequestMapping(value = "chaXunFenYe", method = RequestMethod.GET)
    @ApiOperation(value = "成绩列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "keMuMingCheng",value = "科目名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "xueFen",value = "学分",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "xingMing",value = "姓名",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "nianJi",value = "年级",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "lfenShu",value = "最小分数",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "rfenShu",value = "最大分数",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "xueHao",value = "学号",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> chaXunFenYe(@RequestParam(name = "page") int page,
                                           String keMuMingCheng,
                                           String xueFen,
                                           String xingMing,
                                           String nianJi,
                                           String lfenShu,
                                           String rfenShu,
                                           String xueHao) {
        return this.chengJiServiceImpl.chaXunFenYe(page,keMuMingCheng,xueFen, xingMing, nianJi, lfenShu, rfenShu,xueHao);
    }

    @RequestMapping(value = "chaXunXueFen", method = RequestMethod.GET)
    @ApiOperation(value = "学分查询接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nianJi",value = "年级",paramType = "query",dataType = "String",required = false),

    })
    public Map<String, Object> chaXunXueFen(@RequestParam(name = "page") int page,String nianJi){
        return chengJiServiceImpl.chaXunXueFen(page,nianJi);

    }



//    /**
//     * 查询所有数据
//     * @return 返回所有数据
//     */
//    @RequestMapping(value = "chaXunAll", method = RequestMethod.GET)
//    @ApiOperation(value = "查询所有数据接口",notes = "查询所有数据接口",httpMethod = "GET")
//    public Map<String, Object> chaXunAll() {
//        return this.chengJiServiceImpl.chaXunAll();
//    }


    /**
     *
     */
    @RequestMapping(value = "tiXing", method = RequestMethod.GET)
    @ApiOperation(value = "根据学生电话发送短信提示的接口",notes = "发送短信提示的的接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dianHua",value = "电话",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "xueHao",value = "学号",paramType = "query",dataType = "String",required = true)

    })
    public Map<String, Object> tiXing( String dianHua,String xueHao) {
        Map<String,Object> map=new HashMap<>();
        sendSMS.duanXin(dianHua,xueHao);
        map.put("code",200);
        map.put("msg","发送成功");
        return map;
    }

    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "shanChuById", method = RequestMethod.GET)
    @ApiOperation(value = "删除一条成绩记录接口",notes = "根据一个主键删除一条**记录的接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> shanChuById(@RequestParam("id") String id) {
        return this.chengJiServiceImpl.shanChuById(id);
    }

    /**
     * 通过主键更新单条数据
     *
     * @param chengJi 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "gengXinById", method = RequestMethod.POST)
    @ApiOperation(value = "通过主键更新一个成绩记录的接口",notes = "通过主键更新一个**的接口",httpMethod = "POST")
    public Map<String, Object> gengXinById(@RequestBody @ApiParam(name = "chengJi",value = "pojo模型",required = true) ChengJi chengJi) {
        return this.chengJiServiceImpl.gengXinById(chengJi);
    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param chengJi 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "xinZeng", method = RequestMethod.POST)
    @ApiOperation(value = "新增一个成绩记录的接口",notes = "新增一个成绩记录的接口",httpMethod = "POST")
    public Map<String, Object> xinZeng(@RequestBody @ApiParam(name = "chengJi",value = "pojo模型",required = true) ChengJi chengJi) {
        return this.chengJiServiceImpl.xinZeng(chengJi);
    }

}